package com.commerceE.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.commerceE.dao.AddressDao;
import com.commerceE.dao.DictCityDao;
import com.commerceE.dao.DictProvinceDao;
import com.commerceE.domain.Address;
import com.commerceE.domain.DictCity;
import com.commerceE.service.AddressService;

public class AddressServiceImpl implements AddressService{
	
	@Autowired
	private AddressDao addressDao;
	
	@Autowired
	private DictCityDao dictCityDao;
	
	@Autowired
	private DictProvinceDao dictProvinceDao;

	public List<Address> getAddressByUserId(Long userId){
		 List<Address> addressList = addressDao.getAddressByUserId(userId);
		 if(addressList!=null){
			 for(int i=0;i<addressList.size();i++){
				 Address address = addressList.get(i);
				 address.setStateObject(dictProvinceDao.get(new Long(address.getState())));
				 address.setCityObject(dictCityDao.get(new Long(address.getCity())));
				 List<DictCity> cityList = dictCityDao.getCityListByProvinceId(new Long(address.getState()));
				 address.setCityList(cityList);
			 }
		 }
		return addressList;
	}
	
	public Address getAddressId(Long addressId){
	   Address address = addressDao.get(addressId);
	   address.setStateObject(dictProvinceDao.get(new Long(address.getState())));
	   address.setCityObject(dictCityDao.get(new Long(address.getCity())));
	   return address;
	}
	
	public void insertAddress(Address address){
		addressDao.insert(address);
	}
	
	public void updateAddress(Address address){
		addressDao.update(address);
	}
	
	public void deleteAddress(Long addressId){
		addressDao.delete(addressId);
	}
	
	public AddressDao getAddressDao() {
		return addressDao;
	}

	public void setAddressDao(AddressDao addressDao) {
		this.addressDao = addressDao;
	}

	
	
	
}
